#pragma once

#include <list>
#include <map>
#include "SendCmdToDev.h"

#define PARAM_TYPE_UNKOWN			0
#define PARAM_TYPE_VALUE_RANGE		1
#define PARAM_TYPE_STRING_LIST		2
#define PARAM_TYPE_STRING			3

typedef union
{
	DWORD ui;
	float  f;
	int	   i;
	BOOL   b;
	void*  p;
}VALUE_TYPE;

typedef struct ParamRange
{
	VALUE_TYPE minValue;
	VALUE_TYPE maxValue;
	VALUE_TYPE step;
}VALUE_RANGE;

typedef struct ParamInfo
{
	BOOL valid;
	int type;
	VALUE_TYPE value;
	VALUE_RANGE range;
	std::list<std::string> list;
	std::string strValue;
	ParamInfo()
	{
		valid = FALSE;
		type = PARAM_TYPE_VALUE_RANGE;
		memset(&value,0,sizeof(VALUE_TYPE));
		memset(&range,0,sizeof(VALUE_RANGE));
	};
}DevParam;

typedef struct ExpoParam
{
	DevParam acqMode;
	DevParam shutterTime[2];
	DevParam gain[2];
	DevParam shutterTimeLimit[2];
	DevParam gainLimit[2];
	DevParam adjustMode[2];
	DevParam expectBright[2];
	DevParam meteringRegion[4];
	DevParam trgFrameAdjMode;
	DevParam trgFrameShuttime;
	DevParam trgFrameGain;
	DevParam shutterTimeLowLimit[2];
}CamExpoParam;

typedef struct PreProcParam
{
	DevParam wbEn;
	DevParam wbEnviron;
	DevParam wbCol[3];
	DevParam lutEn;
	DevParam lutMode;
	DevParam lutGamma;
	DevParam imgEnahance;
	DevParam imgDenoise;
	DevParam colorMode;
	DevParam colorSaturation;
	DevParam digiGain;
	DevParam hdrLevel;
	DevParam constrast;
}CamPreprocParam;

typedef struct AcqParam
{
	DevParam format;
	DevParam rotate;
	DevParam fps;
	DevParam afelv;
}CamAcqParam;

typedef struct JPEGParam
{
	DevParam enable;
	DevParam fps;
	DevParam resolution;
	DevParam quality;
}CamJpegParam;

typedef	struct H264Param
{
	DevParam resolution[2];
	DevParam fps[2];
	DevParam profile[2];
	DevParam codeRate[2];
	DevParam iFrame[2];
	DevParam denoiseMode;
	DevParam denoiseLevel;
	DevParam lutEn;
	DevParam lutMode;
	DevParam lutGamma;
	DevParam rtspLocal[2];
	DevParam hdmi;
	DevParam cvbs;
}CamStreamParam;

typedef struct NetParam
{
	DevParam ip;
	DevParam mac;
	DevParam gateway;
	DevParam mask;
	DevParam dnsServer;
	DevParam dhcp;
	DevParam ntpServer;
	DevParam ntpSyncTime;
	DevParam timeZone;
	DevParam ftpServe;
	DevParam ftpServerIP;
	DevParam ftpServerPort;
	DevParam ftpUserName;
	DevParam ftpPassword;
}CamNetParam;

typedef struct IoParam
{
	DevParam pwrSyncEn;
	DevParam pwrSyncPhase;
	DevParam ioNum;
	DevParam isoInNum;
	DevParam isoOutNum;
	DevParam ioConfig[12];
	DevParam isoInConfig[4];
	DevParam isoOutConfig[4];
	DevParam trgFlashEn;
	DevParam fconFlashEn;
	DevParam trgFlashPre;
	DevParam fconFlashPre;
	DevParam flashPulseWidth;
	DevParam flashStrobeFreq;
	DevParam filterSwitch;
	DevParam pwrSyncDelay;
	DevParam UartPortState[3];
	DevParam UartPortBaudRate[3];
	DevParam UartPortWorkMode[3];
	DevParam ledDriverMode;
	DevParam ledDriverStrength;
}CamIOParam;

typedef struct OsdParam
{
	DevParam jpegOsd;
	DevParam h264Osd[2];
}CamOSDParam;

typedef struct IrisParam
{
	DevParam type;
	DevParam pirisStep;
	DevParam pirisF;
	DevParam pirisType;
	DevParam dcirisMode;
}CamIrisParam;

typedef struct StoreParam
{
	DevParam saveJpgtoSD;
	DevParam supportSD;
}CamStoreParam;

typedef struct CmdPortParam
{
	int	nClass;
	int	nClassVer;
	int nPortVer;
	CmdPortParam()
	{
		nClass = 0;
		nClassVer = 0;
		nPortVer = 0;
	};
}CamCmdPortParam;

typedef struct SWModuleInfo
{
	std::string	strName;
	std::string	strVer;
	std::string	strDate;
	std::string	strDescription;
}CamSWModuleInfo;

typedef struct StateParam
{
	DevParam temp;
	int	nSensorWidth;
	int	nSensorHeight;
	std::string	strSeries;
	std::string	strModel;
	std::string	strCpuId;
	std::string	strSN;
	std::string	strHardwareMixVersion;
	std::string	strFirmwareMixVersion;
	std::string	strIp;
	std::string	strMac;
	std::string	strMainBoardVer;
	std::string	strMainBoardMfn;
	std::string	strSensorType;
	std::string	strSensorBoardVer;
	std::string strSD;
	CamSWModuleInfo	moduleInfo[20];
	int	nModuleNum;
	StateParam()
	{
		nSensorWidth = 1920;
		nSensorHeight = 1080;
		nModuleNum = 0;
	};
}CamStateParam;

typedef struct SWRunningParam
{
	BOOL	update;
	BOOL    record;
	SWRunningParam()
	{
		update = FALSE;
		record = FALSE;
	};
}CamSWRunningParam;

class CDevParams
{
public:
	CDevParams(void);
	~CDevParams(void);

public:
	std::map<CString,DWORD> m_mapPortNum;
	CamExpoParam m_camExpo;
	CamPreprocParam m_camPreProc;
	CamAcqParam m_camAcq;
	CamJpegParam m_camJpeg;
	CamStreamParam m_camStream;
	CamNetParam m_camNet;
	CamIOParam m_camIO;
	CamOSDParam m_camOsd;
	CamIrisParam m_camIris;
	CamStoreParam m_camStore;
	CamStateParam m_camState;
	CSendCmdToDev *m_pCmdToDev;
	CamCmdPortParam m_camCmdPort;
	CamSWRunningParam m_camSWRunning;
public:
	int	LoadPortNumInfo(BYTE* pInfo);
	DWORD FindPortNum(CString portName);
	BOOL QueryDevInfo(const char *pIP, int port, char *buff, int size);
	int OpenObtainParams(HWND hWnd, const char* ip, int port, const char* pUsername, const char* pPassword);
	int	CloseObtainParams();
	std::string m_strIP;
	int	m_nPort;
	std::string	m_strUserName;
	std::string	m_strPassword;
	int				AnalyCameraInfo(const char* pVersion);
	char			*m_pchCameraInfo;		
protected:	
	HANDLE m_hThreadGetParam;
	HWND m_hWndNotify;
	HWND m_hWndGetInfo;
	static unsigned __stdcall ThreadGetParams(void * pParam);
};

